﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WCrawlerLib;

namespace WBrowser.MY_CODE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            

            //            if (current_tab_count == 10) return;
            //        TabPage tabPage = new TabPage("Loading...");
            //        tabpages.Add(tabPage);
            //        tabControl1.TabPages.Add(tabPage);
            //        current_tab_count++;
            //        ExtendedWebBrowser browser = new ExtendedWebBrowser();
            //        InitializeBrowserEvents(browser);
            //        webpages.Add(browser);
            //        browser.Parent = tabPage;
            //        browser.Dock = DockStyle.Fill;
            //        browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
            //        browser.DocumentTitleChanged += new EventHandler(Browser_DocumentTitleChanged);
            //        browser.Navigated += Browser_Navigated;
            //        browser.IsWebBrowserContextMenuEnabled = true;
            //        }
            //public void InitializeBrowserEvents(ExtendedWebBrowser browser)
            //    {
            //        browser.NewWindow2 += new EventHandler<NewWindow2EventArgs>(Browser_NewWindow2);
            //    }

            //    void Browser_NewWindow2(object sender, NewWindow2EventArgs e)
            //    {

            //        if (current_tab_count == 10) return;
            //        TabPage tabPage = new TabPage("Loading...");
            //        tabpages.Add(tabPage);
            //        tabControl1.TabPages.Add(tabPage);
            //        current_tab_count++;
            //        ExtendedWebBrowser browser = new ExtendedWebBrowser();
            //        webpages.Add(browser);
            //        browser.Parent = tabPage;
            //        browser.Dock = DockStyle.Fill;
            //        browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
            //        browser.DocumentTitleChanged += new EventHandler(Browser_DocumentTitleChanged);
            //        browser.Navigated += Browser_Navigated;
            //        tabControl1.SelectedTab = tabPage;
            //        browser.Navigate(textBox.Text);

            //        {
            //            e.PPDisp = browser.Application;
            //            InitializeBrowserEvents(browser); 
            //        }
        }

        private void extendedWebBrowser1_NewWindow2(object sender, NewWindow2EventArgs e)
        {
            //Intercepting this event will allow us to create a new form in which
            //we will open the new webpage, to do that we must set the ppDisp property
            //of the NewWindow2EventArgs
            Form1 form1 = new Form1();
            form1.Show();
            e.PPDisp = form1.extendedWebBrowser1.Application;
            //e.PPDisp = this.extendedWebBrowser1.Application;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string data = "agreed=I+agree+to+these+terms&change_lang=&creation_time=1294063116&form_token=8a439668165b0440840e15b2f12124417d46920a";
            //string data = "agreed=I+agree+to+these+terms&change_lang=&creation_time=1294063116&form_token=";
            byte[] postData = Encoding.UTF8.GetBytes(data.ToCharArray());
            string urlString = "http://www.xtremew.org/";
            urlString += @"/ucp.php?mode=register";
            string targetFrameName = "_SELF";
            //string targetFrameName = "_blank";
            string additionalHeaders = "Content-Type: application/x-www-form-urlencoded" + Environment.NewLine;
            //additionalHeaders += "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13" + Environment.NewLine;
            //open in new tab
            //addNewTab();
            extendedWebBrowser1.Navigate(urlString, targetFrameName, postData, additionalHeaders);
        }
    }
}
